﻿<template>
  <a-modal
    title="新增学生3(测试NULL值)"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
		<a-form :form="form">
        <a-form-item label="学生姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入学生姓名" v-decorator="['name', {rules: [{required: true, message: '请输入学生姓名！'}]}]" />
        </a-form-item>
        <a-form-item label="学生年龄" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input-number placeholder="请输入学生年龄" style="width: 100%" v-decorator="['age']" />
        </a-form-item>
        <a-form-item label="零花钱" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入零花钱" v-decorator="['hasMoney']" />
        </a-form-item>
        <a-form-item label="是否在校" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-switch v-decorator="['startName', { valuePropName: 'checked' }]" />
        </a-form-item>
        <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-select style="width: 100%" placeholder="请选择性别" v-decorator="['gender']">
            <a-select-option v-for="(item,index) in genderData" :key="index" :value="item.code">{{ item.name }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择出生日期" v-decorator="['brithDate']" :show-time="{format: 'HH:mm:ss',  defaultValue: [moment('00:00:00', 'HH:mm:ss'),moment('23:59:59', 'HH:mm:ss')]}" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"/>
        </a-form-item>
        <a-form-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择创建时间" v-decorator="['createdTime']" :show-time="{format: 'HH:mm:ss',  defaultValue: [moment('00:00:00', 'HH:mm:ss'),moment('23:59:59', 'HH:mm:ss')]}" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"/>
        </a-form-item>
        <a-form-item label="更新时间" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择更新时间" v-decorator="['updatedTime']" :show-time="{format: 'HH:mm:ss',  defaultValue: [moment('00:00:00', 'HH:mm:ss'),moment('23:59:59', 'HH:mm:ss')]}" value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"/>
        </a-form-item>
        <a-form-item label="创建者名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入创建者名称" v-decorator="['createdUserName']" />
        </a-form-item>
        <a-form-item label="修改者名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入修改者名称" v-decorator="['updatedUserName']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import moment from 'moment'
  import {
  TestStudent3Add
  } from '@/api/modular/main/TestDemo/TestStudent3Manage'
  export default {
  data () {
  return {
  labelCol: {
  xs: { span: 24 },
  sm: { span: 5 }
  },
  wrapperCol: {
  xs: { span: 24 },
  sm: { span: 15 }
  },
  genderData: [],
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
	moment,
      // 初始化方法
      add (record) {
        this.visible = true
        this.$nextTick(() => {

        });
        const genderOption = this.$options
        this.genderData = genderOption.filters['dictData']('sex')
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            TestStudent3Add(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
